/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.full.dialogs;

import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import br.ufmg.dees.insane.commons.dialogs.TabbedDialog;
import br.ufmg.dees.insane.model.disc.element.ParametricElement;
import br.ufmg.dees.insane.model.disc.node.Node;
import br.ufmg.dees.insane.ui.rich.full.InsaneInternalInterface;

/**
 * A class representing creation dialog on screen.
 * This dialog is provided by some tabs like limits,
 * grid and General settings.
 * For example:
 * <pre>
 *    CreateSettingsDialog dgl = new CreateSettingsDialog(parent, this);
 *    dgl.pack();
 * </pre>
 *
 * @author Pitangueira, Roque & Brugiolo, Marco 
 * @version 0.0.1 Beta  
 * @see gui.InsaneInternalInterface
 * @since jdk1.4.1
 */
public final class BodyForcesDialog extends TabbedDialog {

	private static final long serialVersionUID = 1L;
	private InsaneInternalInterface parent;
	private JPanel bodyPane = new JPanel();
	private JPanel bPane = new JPanel();
	private JPanel bPane1 = new JPanel();
	private JTable bTable;
	private String[] bColNames = new String[7];
	private String[][] bCells;

	/**
	 * Constructor method, calling super with the especific title.
	 *
	 * @param parent The parent of the class.
	 * @see gui.InsaneInternalInterface
	 */
	public BodyForcesDialog(InsaneInternalInterface parent, ParametricElement element) {
		this.parent = parent;
		int aux = element.getIncidence().size();
		
		bColNames[0] = parent.getResourceBundle().getString("dBodyForDialog01");
		bColNames[1] = "Fx";
		bColNames[2] = "Fy";
		bColNames[3] = "Fz";
		bColNames[4] = "Mx";
		bColNames[5] = "My";
		bColNames[6] = "Mz";
		
		bCells = new String[aux][4];
		for(int i = 0; i < aux; i++) {
			bCells[i][0] = ((Node)(element.getIncidence().get(i))).getLabel();
		}

		// Sets up the material panel
		bodyPane.setLayout(new BoxLayout(bodyPane, BoxLayout.Y_AXIS));
		bPane.setLayout(new BoxLayout(bPane, BoxLayout.X_AXIS));
		bodyPane.add(bPane);

		bPane1.setLayout(new GridLayout(1,4,0,0));
		bPane.add(bPane1);
		if ( aux>=25 )
			bPane.add( new JLabel("    ") );

		bPane1.add( new JButton(parent.getResourceBundle().getString("dBodyForDialog01")) );
		bPane1.add( new JButton("Fx") );
		bPane1.add( new JButton("Fy") );
		bPane1.add( new JButton("Mz") );

		JPanel bfPane = new JPanel();
		bodyPane.add(bfPane);
		bfPane.setLayout(new GridLayout(1,1,0,0));

		bTable = new JTable(bCells, bColNames);
		if ( aux<26 ) {
			bfPane.add( bTable );
		} else {
			bfPane.add(new JScrollPane(bTable), "Center");
		}
		String label = parent.getResourceBundle().getString("dBodyForDialog02")+ " " + element.getLabel();
		addTab(label, bodyPane);

	}

	public int showDialog() {
		return super.showDialog(parent, parent.getResourceBundle().getString("dBodyForDialog03") + "     :");
	}

	/**
	 * This method is executed on OK button click.
	 */
	public void approvedPerform() {
		try {
			this.setVisible(false);
		} catch (Exception e) {
			Toolkit.getDefaultToolkit().beep();
			this.setVisible(false);
		}
	}

	/** Returns the Body Force of the element.
	*@return The Body Force of the element.
	*/
	public String[][] getBodyForce() {
		return bCells;
	}

}